# 获取文件
with open('C:\\Users\\Administrator\\Desktop\\text.txt','r',encoding = 'UTF-8') as f:
    # 读取文件
    result = f.read()
    # 调用字符串count方式，并输入要查找的内容
    print(result.count('python'))

with open ("C:\\Users\\Administrator\\Desktop\\my_diary.txt","r",encoding = "UTF-8") as f :
    result = f.read()
    print (result)
    # 使用 split('\n') 将文本内容按换行符分割成字符串列表 str_list
    str_list = result.split('\n')
    # 遍历列表 str_list，通过计数器 count 累加统计总行数，并最终打印结果
    count = 0
    for i in str_list:
        count += 1
    print (f"总行数为：{count}")